import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

export default defineConfig(({ mode }) => {
  if (mode === 'lib') {
    return {
      plugins: [vue()],
      build: {
        lib: {
          entry: resolve(__dirname, 'src/index.js'),
          name: 'Vue3FormMaking',
          fileName: (format) => `vue3-form-making.${format}.js`
        },
        rollupOptions: {
          external: ['vue', 'element-plus', 'vue-i18n'],
          output: {
            globals: {
              vue: 'Vue',
              'element-plus': 'ElementPlus',
              'vue-i18n': 'VueI18n'
            }
          }
        }
      }
    }
  }

  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    }
  }
})